<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets">
    <h:head>
        <title>Tiendalia - Administración Pedidos</title>
    </h:head>
    <h:body>
        <ui:composition template="template.xhtml">
            <ui:define name="sidebar">
                <ui:include src="adminmenu.xhtml"/>
            </ui:define>
            <ui:define name="content">
                <p:dataTable id="ordersTable" styleClass="adminTable" var="order" value="#{admOrdersBean.orders}">
                    <f:facet name="header">
                        <h:outputText styleClass="headerTitle" value="Pedidos" />
                    </f:facet>
                    <p:column style="width:2%">
                        <p:rowToggler />
                    </p:column>
                    <p:column headerText="Código Pedido">
                        <h:outputText value="#{order.id}" />
                    </p:column>
                    <p:column headerText="Usuario">
                        <h:outputText value="#{order.customer.email}" />
                    </p:column>
                    <p:column headerText="Fecha">
                        <h:outputText value="#{order.orderDate}">
                            <f:convertDateTime type="both" locale="es_ES" pattern="dd/MM/yyyy HH:mm:ss" timeZone="GMT+2" />
                        </h:outputText>
                    </p:column>
                    <p:column headerText="Importe">
                        <h:outputText value="#{order.total}">
                            <f:convertNumber currencySymbol="€" type="currency" />
                        </h:outputText>
                    </p:column>
                    <p:rowExpansion>
                        <p:dataTable id="prodsTable" styleClass="detailTable" var="product" value="#{order.orderProducts}">
                            <f:facet name="header">
                                <h:outputText styleClass="headerTitle" value="Detalle de pedido ##{order.id}" />
                            </f:facet>
                            <p:column headerText="Nombre">
                                <h:outputText value="#{product.item.name}" />
                            </p:column>
                            <p:column headerText="Cantidad">
                                <h:outputText value="#{product.quantity}" />
                            </p:column>
                            <p:column headerText="Precio">
                                <h:outputText value="#{product.purchasePrice}" >
                                    <f:convertNumber currencySymbol="€" type="currency" />
                                </h:outputText>
                            </p:column>
                            <p:column headerText="Total">
                                <h:outputText value="#{product.total}">
                                    <f:convertNumber currencySymbol="€" type="currency" />
                                </h:outputText>
                            </p:column>
                        </p:dataTable>
                    </p:rowExpansion>
                </p:dataTable>
            </ui:define>
        </ui:composition>
    </h:body>
</html>

